package com.zhijiang.hospital.service.impl;

import com.zhijiang.hospital.entity.ComEmployee;
import com.zhijiang.hospital.entity.dto.MeetingEmployeeDto;
import com.zhijiang.hospital.mapper.EmpolyeeMapper;
import com.zhijiang.hospital.mapper.MeetingEmployeeMapper;
import com.zhijiang.hospital.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
@Slf4j
public class DeptServiceImpl implements DeptService {

    @Autowired
    MeetingEmployeeMapper meetingEmployeeMapper;
    @Autowired
    EmpolyeeMapper empolyeeMapper;

    @Override
    public List<MeetingEmployeeDto> queryAll() {

        List<MeetingEmployeeDto> emplyeeDept = meetingEmployeeMapper.getAll().stream().filter(s -> !s.getDeptCode().equals("1126")).collect(Collectors.toList());

//        emplyeeDept.stream().forEach(s->{
//            List<ComEmployee> comEmployee = empolyeeMapper.getAll(s.getDeptCode());
//            if(comEmployee.size()>0){
//                s.setComEmployees(comEmployee);
//            }
//        });
        for (MeetingEmployeeDto dto : emplyeeDept) {
            List<ComEmployee> comEmployee = empolyeeMapper.getAll(dto.getDeptCode());

            if (comEmployee.size() > 0) {
                dto.setComEmployees(comEmployee);
                dto.setLabel(dto.getDeptName());
                for (ComEmployee employee : comEmployee) {
//                   employee.setLabel(employee.getEmplName());
                }
            }

        }
        List<MeetingEmployeeDto> collect = emplyeeDept.stream().filter(s -> s.getComEmployees() != null).collect(Collectors.toList());

        log.info("部门：" + collect.size());
        return collect;
    }
}
